package chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UdpSenderDemo01 {
    public static void main(String[] args) throws Exception {

        DatagramSocket socket = new DatagramSocket(8888);
        while(true){
            //准备数据：控制台读取 System.in
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            //发包内数据
            String data = reader.readLine();
            byte[] datas = data.getBytes();
            DatagramPacket packet = new DatagramPacket(datas,0,datas.length,new InetSocketAddress("localhost",6666));
            //发送包
            socket.send(packet);

            if (data.equals("bye")){
                break;
            }
        }
        //关闭流
        socket.close();
    }
}
